package li.kaeppe.travel.tracker.domain;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.security.GrantedAuthority;

@Entity
@Table(name="TT_ROLE")
@javax.persistence.SequenceGenerator(name="SEQ_ROLE", sequenceName="ROLE_SEQUENCE")
public class UserRole implements GrantedAuthority {

	/* **************************************************** */
	/*                      CONSTANTS                       */
	/* **************************************************** */

	private static final long serialVersionUID = -5978364684827915395L;
	
	/* **************************************************** */
	/*                     MEMBER FIELDS                    */
	/* **************************************************** */

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_ROLE")
	private long id;
	
	@Basic
	String role;
	
	@Basic 
	String description;
	
	/* **************************************************** */
	/*                      CONSTRUCTOR                     */
	/* **************************************************** */

	/* **************************************************** */
	/*                    PUBLIC METHODS                    */
	/* **************************************************** */

	public String getAuthority() {
		return getRole();
	}

	public int compareTo(Object o) {
		if(o instanceof String) {
			return getRole().compareTo((String)o);
		} else {
			return -1;
		}
	}
	
	public String toString() {
		return this.getRole() + "[" + this.getDescription() + "]";
	}
	
	/* **************************************************** */
	/*                  PROTECTED METHODS                   */
	/* **************************************************** */

	/* **************************************************** */
	/*                   PRIVATE METHODS                    */
	/* **************************************************** */

	/* **************************************************** */
	/*                  GETTERS AND SETTERS                 */
	/* **************************************************** */

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
}
